package com.gisocn.onemap.base;

import com.gisocn.onemap.net.ApiClient;
import com.gisocn.onemap.net.ApiService;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/* loaded from: classes.dex */
public class BasePresenter<V> {
    protected ApiService apiService;
    private CompositeDisposable mCompositeDisposable;
    public V mvpView;

    public void attachView(V v) {
        this.mvpView = v;
        this.apiService = (ApiService) ApiClient.retrofit().create(ApiService.class);
    }

    public void detachView() {
        this.mvpView = null;
        onUnSubscribe();
    }

    public void onUnSubscribe() {
        CompositeDisposable compositeDisposable = this.mCompositeDisposable;
        if (compositeDisposable != null) {
            compositeDisposable.dispose();
        }
    }

    public void addSubscription(Observable observable, DisposableObserver disposableObserver) {
        if (this.mCompositeDisposable == null) {
            this.mCompositeDisposable = new CompositeDisposable();
        }
        this.mCompositeDisposable.add(disposableObserver);
        observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(disposableObserver);
    }
}
